package day15.atm;

import day11.afternoon.Bowl;
import day11.afternoon.Chopsticks;

public class SuperArray {
    private Object[] objects = new Object[0];
    /**
     * 增加元素到数组中
     * @param value
     */
    public void add(Object value){
        Object[] newObjects = new Object[objects.length + 1];
        for (int i = 0;i < objects.length;i++){
            newObjects[i] = objects[i];
        }
        newObjects[newObjects.length - 1] = value;
        objects = newObjects;
    }

    /**
     * 删除指定下标元素
     * @param index
     */
    public void remove(int index){
        Object[] newObjects = new Object[objects.length - 1];
        for (int i = 0;i < newObjects.length;i++){
            if (i < index){
                newObjects[i] = objects[i];
            }else {
                newObjects[i] = objects[i + 1];
            }
        }
        objects = newObjects;

    }

    /**
     * 根据下标获取指定元素
     */
    public Object get(int index){
        return objects[index];
    }

    /**
     * 获取数组长度
     * @return
     */
    public int size(){
        return objects.length;
    }

    public static void main(String[] args) {
        day11.afternoon.SuperArray ary = new day11.afternoon.SuperArray();
        ary.add('A');
        ary.add("hello");
        ary.add(1000);
        ary.add(50.0);
        ary.add(new Chopsticks("筷子","竹子"));
        ary.add(new Bowl("碗","陶瓷泥"));

        ary.remove(2);
        System.out.println(ary.size());
        System.out.println(ary.get(2));

        for (int i = 0;i < ary.size();i++){
            System.out.print(ary.get(i) + "  ");
        }
    }
}
